📄 cwindow.cpp
字号:
if (READ_PROPERTY) GB.ReturnObject(THIS->mask); else { GB.StoreObject(PROP(GB_OBJECT), (void **)&THIS->mask); WINDOW->defineMask(); } }END_PROPERTYBEGIN_PROPERTY(CWINDOW_state) if (!THIS->window) { if (READ_PROPERTY) GB.ReturnInteger(0); } else { if (READ_PROPERTY) GB.ReturnInteger(WINDOW->getState()); else WINDOW->setState(VPROP(GB_INTEGER)); }END_PROPERTYBEGIN_PROPERTY(CWINDOW_top_only) if (READ_PROPERTY) { GB.ReturnBoolean(THIS->topOnly); return; } if (THIS->embedded) return; if ((THIS->topOnly == 0) == (VPROP(GB_BOOLEAN) == 0)) return; THIS->topOnly = VPROP(GB_BOOLEAN); WINDOW->setTopOnly(VPROP(GB_BOOLEAN));END_PROPERTYBEGIN_PROPERTY(CWINDOW_skip_taskbar) if (READ_PROPERTY) { GB.ReturnBoolean(THIS->skipTaskbar); return; } if (THIS->embedded) return; if ((THIS->skipTaskbar == 0) == (VPROP(GB_BOOLEAN) == 0)) return; THIS->skipTaskbar = VPROP(GB_BOOLEAN); WINDOW->setSkipTaskbar(VPROP(GB_BOOLEAN));END_PROPERTYBEGIN_METHOD_VOID(CWINDOW_center) if (THIS->embedded) return; WINDOW->center(true);END_METHODBEGIN_METHOD_VOID(CWINDOW_delete) //qDebug("CWINDOW_delete %p", THIS); do_close(THIS, 0); if (THIS->window) CWIDGET_clear_flag(THIS, WF_PERSISTENT); CWIDGET_destroy((CWIDGET *)THIS);END_METHODBEGIN_PROPERTY(CWINDOW_visible) if (READ_PROPERTY) GB.ReturnBoolean(!WINDOW->isHidden()); else { if (VPROP(GB_BOOLEAN)) WINDOW->showActivate(); else WINDOW->hide(); }END_PROPERTY/*BEGIN_PROPERTY(CWINDOW_design) if (READ_PROPERTY) { GB.ReturnBoolean(CWIDGET_test_flag(_object, WF_WIN_DESIGN)); return; } if (PROPERTY(char)) { CWIDGET_set_flag(_object, WF_WIN_DESIGN); } else { CWIDGET_clear_flag(_object, WF_WIN_DESIGN); }END_PROPERTY*//*BEGIN_PROPERTY(CWINDOW_workspace) CWINDOW *win = OBJECT(CWINDOW); if (READ_PROPERTY) GB.ReturnBoolean(win->container->isA("QWorkspace")); else { if (win->container->children() != 0) { GB.Error("Property is read-only"); return; } delete win->container; if (PROPERTY(char)) win->container = new QWorkspace(WIDGET); else win->container = new QFrame(WIDGET); }END_PROPERTY*//*************************************************************************** D�larations***************************************************************************/GB_DESC CWindowMenusDesc[] ={ GB_DECLARE(".WindowMenus", 0), GB_VIRTUAL_CLASS(), GB_METHOD("_next", "Menu", CWINDOW_menu_next, NULL), GB_PROPERTY_READ("Count", "i", CWINDOW_menu_count), GB_END_DECLARE};/*GB_DESC CWindowToolBarsDesc[] ={ GB_DECLARE(".Window.ToolBars", 0), GB_VIRTUAL_CLASS(), GB_METHOD("Add", NULL, CWINDOW_toolbar_add, "'Toolbar'Toolbar;"), GB_METHOD("Remove", NULL, CWINDOW_toolbar_remove, "'Toolbar'Toolbar;"), GB_END_DECLARE};*/GB_DESC CWindowDesc[] ={ GB_DECLARE("Window", sizeof(CWINDOW)), GB_INHERITS("Container"), GB_CONSTANT("None", "i", 0), GB_CONSTANT("Fixed", "i", 1), GB_CONSTANT("Resizable", "i", 2), GB_CONSTANT("Normal", "i", 0), GB_CONSTANT("Minimized", "i", 1), GB_CONSTANT("Maximized", "i", 2), GB_CONSTANT("FullScreen", "i", 3), GB_STATIC_METHOD("_init", NULL, CWINDOW_init, NULL), GB_METHOD("_new", NULL, CWINDOW_new, "[(Parent)Control;]"), GB_METHOD("_free", NULL, CWINDOW_free, NULL), //GB_STATIC_METHOD("Dialog", "i", CWINDOW_dialog, NULL), GB_METHOD("Close", "b", CWINDOW_close, "[(Return)i]"), GB_METHOD("Raise", NULL, CWINDOW_raise, NULL), GB_METHOD("Show", NULL, CWINDOW_show, NULL), GB_METHOD("ShowModal", "i", CWINDOW_show_modal, NULL), GB_METHOD("ShowDialog", "i", CWINDOW_show_modal, NULL), GB_METHOD("Center", NULL, CWINDOW_center, NULL), GB_PROPERTY_READ("Modal", "b", CWINDOW_modal), //GB_STATIC_METHOD("Dialog", "i", CWINDOW_dialog, NULL), GB_METHOD("Delete", NULL, CWINDOW_delete, NULL), /* GB_PROPERTY_READ("ScreenX", "i", CWINDOW_x), GB_PROPERTY_READ("ScreenY", "i", CWINDOW_y), GB_PROPERTY("X", "i", CWINDOW_x), GB_PROPERTY("Y", "i", CWINDOW_y), GB_PROPERTY("W", "i", CWINDOW_w), GB_PROPERTY("H", "i", CWINDOW_h), GB_PROPERTY("Left", "i", CWINDOW_x), GB_PROPERTY("Top", "i", CWINDOW_y), GB_PROPERTY("Width", "i", CWINDOW_w), GB_PROPERTY("Height", "i", CWINDOW_h), */ GB_PROPERTY("Persistent", "b", CWINDOW_persistent), GB_PROPERTY("Text", "s", CWINDOW_text), GB_PROPERTY("Title", "s", CWINDOW_text), GB_PROPERTY("Caption", "s", CWINDOW_text), GB_PROPERTY("Icon", "Picture", CWINDOW_icon), GB_PROPERTY("Border", "i<Window,None,Fixed,Resizable>", CWINDOW_border), GB_PROPERTY("State", "i<Window,Normal,Minimized,Maximized,FullScreen>", CWINDOW_state), GB_PROPERTY("TopOnly", "b", CWINDOW_top_only), GB_PROPERTY("SkipTaskbar", "b", CWINDOW_skip_taskbar), GB_PROPERTY("Visible", "b", CWINDOW_visible), GB_PROPERTY("Arrangement", "i<Arrange>", CCONTAINER_arrangement), //GB_PROPERTY("AutoResize", "b", CCONTAINER_auto_resize), GB_PROPERTY("Padding", "i", CCONTAINER_padding), GB_PROPERTY("Spacing", "i", CCONTAINER_spacing), //GB_PROPERTY("Picture", "Picture", CWINDOW_picture), GB_PROPERTY("Mask", "Picture", CWINDOW_mask), GB_PROPERTY_SELF("Menus", ".WindowMenus"), GB_PROPERTY_READ("Id", "i", CWINDOW_id), GB_PROPERTY_READ("Handle", "i", CWINDOW_id), GB_CONSTANT("_Properties", "s", CWINDOW_PROPERTIES), GB_CONSTANT("_DefaultEvent", "s", "Open"), GB_CONSTANT("_Arrangement", "i", ARRANGE_FILL), //GB_EVENT("Delete", NULL, NULL, &EVENT_Destroy), GB_EVENT("Close", "b", NULL, &EVENT_Close), GB_EVENT("Open", NULL, NULL, &EVENT_Open), GB_EVENT("Activate", NULL, NULL, &EVENT_Activate), GB_EVENT("Deactivate", NULL, NULL, &EVENT_Deactivate), GB_EVENT("Move", NULL, NULL, &EVENT_Move), GB_EVENT("Resize", NULL, NULL, &EVENT_Resize), GB_EVENT("Show", NULL, NULL, &EVENT_Show), GB_EVENT("Hide", NULL, NULL, &EVENT_Hide), GB_END_DECLARE};GB_DESC CWindowsDesc[] ={ GB_DECLARE("Windows", 0), GB_VIRTUAL_CLASS(), GB_STATIC_METHOD("_next", "Window", CWINDOW_next, NULL), GB_STATIC_METHOD("_get", "Window", CWINDOW_get, "(Id)i"), GB_STATIC_PROPERTY_READ("Count", "i", CWINDOW_count), GB_END_DECLARE};GB_DESC CFormDesc[] ={ GB_DECLARE("Form", sizeof(CFORM)), GB_INHERITS("Window"), GB_AUTO_CREATABLE(), GB_STATIC_METHOD("Main", NULL, CFORM_main, NULL), GB_STATIC_METHOD("Load", NULL, CFORM_load, "[(Parent)Control;]"), GB_METHOD("_new", NULL, CFORM_new, NULL), GB_END_DECLARE};/*************************************************************************** MyMainWindow***************************************************************************/#if QT_VERSION >= 0x030005MyMainWindow::MyMainWindow(QWidget *parent) : QMainWindow::QMainWindow(parent, 0, Qt::WType_TopLevel | (parent ? 0 : Qt::WGroupLeader)) //, 0, Qt::WType_TopLevel) // | (parent ? copy->getWFlags() : 0)) // | Qt::WDestructiveClose)#elseMyMainWindow::MyMainWindow(QWidget *parent) : QMainWindow::QMainWindow(0) //, 0, Qt::WType_TopLevel) // | (copy ? copy->getWFlags() : 0)) // | Qt::WDestructiveClose)#endif{ db = 0; cb = 0; sg = 0; shown = false; border = BorderResizable; state = StateNormal; mustCenter = false; _activate = false; mdichild = parent && parent->isA("QWorkspace"); if (mdichild) clearWFlags(WType_TopLevel); //qDebug("MyMainWindow: %p -> %p", this, parentWidget()); /*if (!parent) { qDebug("GroupLeader!"); setWFlags(WGroupLeader); }*/ //qDebug("parent = %p", parentWidget());}MyMainWindow::~MyMainWindow(){ CWINDOW *ob = (CWINDOW *)CWidget::get(this); //qDebug("~MyMainWindow %p ob = %p", this, ob); if (sg) delete sg; if (ob == NULL) { qWarning("~MyMainWindow: ob == NULL"); return; } //do_close(ob, 0, true); GB.Detach(ob); if (!mdichild) { if (ob->menu) CMenu::unrefChildren(ob->menu); CWindow::dict.remove(ob); //if (ob == window_main) // window_main = NULL; CWindow::count = CWindow::dict.count(); //qDebug("~MyMainWindow: CWindow::count = %d (%p %s)", CWindow::count, ob, ob->embedded ? "E" : "W"); MAIN_check_quit(); } //qDebug("~MyMainWindow %p (end)", this);}void MyMainWindow::setCancelButton(QPushButton *pb, bool on){ if (on) { cb = pb; } else { if (pb == cb) cb = 0; }}void MyMainWindow::setDefaultButton(QPushButton *pb, bool on){ //qDebug("setDefaultButton: %s %s", pb->text().latin1(), on ? "true" : "false"); if (on) { if (db) db->setDefault(false); db = pb; db->setDefault(true); } else { if (pb == db) { db->setDefault(false); db = 0; } }}int MyMainWindow::getState(){ if (isHidden()) return state; if (isMinimized()) return StateMinimized; else if (isMaximized()) return StateMaximized; #if QT_VERSION >= 0x030100 else if (isFullScreen()) return StateFullScreen; #endif else return StateNormal;}void MyMainWindow::setState(int s){ #ifdef DEBUG_STATE qDebug("setState(%d)", s); #endif if (s < 0 || s > 3) return; if (!isHidden() && s == getState()) { //qDebug("show"); show(); return; } state = s; if (shown) { switch(state) { case StateNormal: #ifdef DEBUG_STATE qDebug("showNormal()"); #endif showNormal(); break; case StateMinimized: #ifdef DEBUG_STATE qDebug("showMinimized()"); #endif showMinimized(); break; case StateMaximized: #ifdef DEBUG_STATE qDebug("showMaximized()"); #endif showMaximized(); break; case StateFullScreen: #ifdef DEBUG_STATE qDebug("showFullScreen()"); #endif showFullScreen(); break; default: #ifdef DEBUG_STATE qDebug("state = %d ??", state); #endif break; } #if QT_VERSION < 0x030102 switch(state) { case StateNormal: case StateMaximized: case StateFullScreen: qDebug("XMapWindow"); XMapWindow(x11Display(), winId()); XFlush(x11Display()); //XSetInputFocus(x11Display(), winId(), RevertToNone, CurrentTime); break; default: break; } #endif }}void MyMainWindow::showEvent(QShowEvent *e){ if (_activate) { raise(); setActiveWindow(); _activate = false; }}void MyMainWindow::showActivate(){ CWIDGET *_object = CWidget::get(this); int st; //qDebug(">> Show %d %d %d %d", x(), y(), width(), height()); if (CWIDGET_test_flag(THIS, WF_IN_CLOSE) || CWIDGET_test_flag(THIS, WF_IN_SHOW)) { //qDebug("Showing form during a close event !"); return; } //qDebug("showActivate %p", _object); CWIDGET_set_flag(THIS, WF_IN_SHOW); CWIDGET_clear_flag(THIS, WF_CLOSED); if (!THIS->embedded) { setTopOnly(THIS->topOnly); setSkipTaskbar(THIS->skipTaskbar); } if (!shown) { GB.Raise(THIS, EVENT_Open, 0); } st = getState(); if (!shown) { shown = true; setState(st); //THIS->x = x(); //THIS->y = y(); /*if (THIS->window && THIS->embedded) { qDebug("CWorkspace: install event filter: %p %s", parentWidget(), parentWidget()->className()); parentWidget()->installEventFilter(&CWorkspace::manager); }*/ GB.Raise(THIS, EVENT_Move, 0); GB.Raise(THIS, EVENT_Resize, 0); } else { if (st == StateMinimized) { setState(StateNormal); _activate = true; } else if (!isVisible()) { //qDebug("#1"); show(); //if (THIS->embedded) // setFocus(); } else { if (THIS->embedded) { //qDebug("#2"); //setActiveWindow(); //raise(); //workspace->setFocus(); setFocus(); //show(); } else { //qDebug("#3"); raise(); setActiveWindow(); } } } defineMask(); CWIDGET_clear_flag(THIS, WF_IN_SHOW); //qDebug("<< showActivate"); //qDebug("showActivate: %p parent = %p x = %d y = %d", this, parentWidget(), mapToGlobal(QPoint(0, 0)).x(), mapToGlobal(QPoint(0, 0)).y());}void MyMainWindow::showModal(void){ WFlags flags = getWFlags(); CWIDGET *_object = CWidget::get(this); bool persistent = CWIDGET_test_flag(THIS, WF_PERSISTENT); QWidget *parent = parentWidget(); QWidget *reparent; CWINDOW *save = CWINDOW_Current; QPoint p = pos(); if (testWFlags(WShowModal)) return; //setWFlags( WShowModal ); //QPoint p((qApp->desktop()->width() - width()) / 2, (qApp->desktop()->height() - height()) / 2); //clearWFlags(WStyle_Minimize); //clearWFlags(WStyle_SysMenu); //reparent(parentWidget(), WType_Dialog | WShowModal | WStyle_DialogBorder | (getWFlags() & 0xffff0000 & ~WStyle_SysMenu), p); //reparent(parentWidget(), WShowModal | WStyle_NormalBorder | WStyle_Title | WStyle_ContextHelp | (getWFlags() & 0xffff0000), p); /*p.setX((qApp->desktop()->width() - width()) / 2); p.setY((qApp->desktop()->height() - height()) / 2); doReparent(CWINDOW_Current, getWFlags(), p); if (CWINDOW_Current) move(x() - parentWidget()->x(), y() - parentWidget()->y());*/ //setWFlags(WType_Dialog | WShowModal | WStyle_DialogBorder | WStyle_Dialog); mustCenter = true; /*if (parentWidget()) { p.setX(p.x() - parentWidget()->pos().x()); p.setY(p.y() - parentWidget()->pos().y()); }*/ reparent = qApp->activeWindow(); if (!reparent && CWINDOW_Main) { reparent = CWINDOW_Main->widget.widget; if (reparent == this) reparent = 0; } #if QT_VERSION >= 030300 doReparent(reparent, getWFlags() | WStyle_DialogBorder | WShowModal, p); #else doReparent(reparent, getWFlags() | WType_Dialog | WShowModal | WStyle_DialogBorder | WStyle_Dialog, p); #endif if (border == BorderResizable) setSizeGrip(true); //XSetTransientForHint(x11Display(), winId(), None ); showActivate(); CWINDOW_Current = THIS; qApp->eventLoop()->enterLoop(); CWINDOW_Current = save; if (persistent) { setSizeGrip(false); clearWState(WShowModal); setWFlags(flags); doReparent(parent, flags, p); } /* Gets the customed destroy event immediately */ //qApp->eventLoop()->processEvents(QEventLoop::ExcludeUserInput);}/*void MyMainWindow::hide(void){ CWIDGET *_object = CWidget::get(this); QMainWindow::hide(); if (THIS->topOnly) setTopOnly(true);}*/void MyMainWindow::setTopOnly(bool top){ CWINDOW_change_property(this, _atom_net_wm_state_above, top); CWINDOW_change_property(this, _atom_net_wm_state_stays_on_top, top); //#if QT_VERSION < 0x030200 //bool hasIcon; //#endif //QPixmap p; //WFlags flags; //QWidget *parent; #if 0 flags = getWFlags(); if (top) { flags |= WStyle_StaysOnTop; //flags |= WX11BypassWM; /*if (border == BorderNone) flags |= WType_Popup; else flags |= WType_Popup;*/ //parent = 0; } else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -