void JXDisplayMenu::BuildMenu() { RemoveAllItems(); JXApplication* app = JXGetApplication(); const JSize count = app->GetDisplayCount(); for (JIndex i=1; i<=count; i++) { JXDisplay* display = app->GetDisplay(i); AppendItem(display->GetName(), kRadioType); } ShowSeparatorAfter(count); AppendItem(kNewDisplayStr); itsNewDisplayIndex = count+1; SetUpdateAction(kDisableNone); const JBoolean found = (JXGetApplication())->GetDisplayIndex(GetDisplay(), &itsDisplayIndex); assert( found ); ListenTo(this); ListenTo( (JXGetApplication())->GetDisplayList() ); }
JXDocumentManager::JXDocumentManager ( const JBoolean wantShortcuts ) : itsWantShortcutFlag( wantShortcuts ) { itsDocList = new JArray<DocInfo>; assert( itsDocList != NULL ); itsDocList->SetCompareFunction(CompareDocNames); itsDocList->SetSortOrder(JOrderedSetT::kSortAscending); itsNewDocCount = 0; itsFileMap = new JArray<FileMap>; assert( itsFileMap != NULL ); itsPerformSafetySaveFlag = kJTrue; itsSafetySaveTask = new JXTimerTask(kDefaultSafetySavePeriod); assert( itsSafetySaveTask != NULL ); ListenTo(itsSafetySaveTask); itsUpdateDocMenuTask = NULL; JXDisplay* d = (JXGetApplication())->GetCurrentDisplay(); itsDefaultMenuIcon = new JXImage(d, d->GetColormap(), jx_plain_file_small); assert( itsDefaultMenuIcon != NULL ); JXSetDocumentManager(this); }
void JXAssert::UnlockDisplays() { const JSize count = itsDisplayList->GetElementCount(); for (JIndex i=1; i<=count; i++) { JXDisplay* display = itsDisplayList->NthElement(i); Display* xDisplay = display->GetXDisplay(); XUngrabServer(xDisplay); XUngrabPointer(xDisplay, CurrentTime); XUngrabKeyboard(xDisplay, CurrentTime); display->Flush(); } }
JBoolean JXApplication::Close() { assert( itsRequestQuitFlag ); const JSize count = itsDisplayList->GetElementCount(); for (JIndex i=1; i<=count; i++) { JXDisplay* display = itsDisplayList->NthElement(i); (display->GetMenuManager())->CloseCurrentMenus(); } return JXDirector::Close(); // deletes us if successful }
JBoolean JXDockWidget::CloseAll() { if (itsWindowList != NULL) { JXDisplay* display = GetDisplay(); Display* xDisplay = display->GetXDisplay(); const JSize count = itsWindowList->GetElementCount(); for (JIndex i=count; i>=1; i--) { JXWindow* w = itsWindowList->NthElement(i); StopListening(w); Window xWindow = w->GetXWindow(); if (w->Close()) { if (JXDisplay::WindowExists(display, xDisplay, xWindow)) { w->Undock(); } else if ((JXGetApplication())->DisplayExists(xDisplay)) { itsTabGroup->DeleteTab(i); itsWindowList->RemoveElement(i); } else { return kJFalse; } } else { UpdateMinSize(); return kJFalse; } } delete itsWindowList; itsWindowList = NULL; UpdateMinSize(); } return kJTrue; }
void JXApplication::HandleOneEvent() { itsHadBlockingWindowFlag = kJFalse; UpdateCurrentTime(); const JBoolean allowSleep = HandleCustomEvent(); UpdateCurrentTime(); JBoolean hasEvents = kJFalse; JPtrArrayIterator<JXDisplay> iter(itsDisplayList); JXDisplay* display; JIndex displayIndex = 0; while (iter.Next(&display)) { displayIndex++; itsCurrDisplayIndex = displayIndex; // itsCurrDisplayIndex might change during event if (XPending(*display) != 0) { hasEvents = kJTrue; // get the next event XEvent xEvent; XNextEvent(*display, &xEvent); if (xEvent.type != MotionNotify) { itsLastIdleTime = itsCurrentTime; } // dispatch the event display->HandleEvent(xEvent, itsCurrentTime); } else { display->Idle(itsCurrentTime); } } PopAllIdleTaskStack(); PerformTasks(hasEvents, allowSleep); }
JBoolean JXApplication::FindDisplay ( const Display* xDisplay, JXDisplay** display ) { const JSize count = itsDisplayList->GetElementCount(); for (JIndex i=1; i<=count; i++) { JXDisplay* d = itsDisplayList->NthElement(i); if (d->GetXDisplay() == xDisplay) { *display = d; return kJTrue; } } *display = NULL; return kJFalse; }
TestWidget::TestWidget ( const JBoolean isMaster, const JBoolean isImage, JXMenuBar* menuBar, JXScrollbarSet* scrollbarSet, JXContainer* enclosure, const HSizingOption hSizing, const VSizingOption vSizing, const JCoordinate x, const JCoordinate y, const JCoordinate w, const JCoordinate h ) : JXScrollableWidget(scrollbarSet, enclosure, hSizing, vSizing, x,y, w,h), itsRNG() { JIndex i; itsFillFlag = kJFalse; itsRandPointCount = 10; itsResizeDialog = NULL; SetBackColor(GetColormap()->GetDefaultBackColor()); // cursors JXDisplay* display = GetDisplay(); itsTrekCursor = display->CreateBuiltInCursor("XC_trek", XC_trek); itsGumbyCursor = display->CreateBuiltInCursor("XC_gumby", XC_gumby); itsBogosityCursor = display->CreateBuiltInCursor("XC_bogosity", XC_bogosity); itsFleurCursor = display->CreateBuiltInCursor("XC_fleur", XC_fleur); SetDefaultCursor(itsTrekCursor); // menus itsActionsMenu = menuBar->AppendTextMenu(kActionsMenuTitleStr); itsActionsMenu->SetTitleFontStyle(GetColormap()->GetWhiteColor()); itsActionsMenu->SetShortcuts(kActionsMenuShortcutStr); itsActionsMenu->SetMenuItems(kActionsMenuStr); itsActionsMenu->SetUpdateAction(JXMenu::kDisableNone); ListenTo(itsActionsMenu); itsPointMenu = jnew JXTextMenu(itsActionsMenu, kPointMenuCmd, menuBar); assert( itsPointMenu != NULL ); itsPointMenu->SetMenuItems(kPointMenuStr); itsPointMenu->SetUpdateAction(JXMenu::kDisableNone); ListenTo(itsPointMenu); // This tests the JX response to an empty menu. JXTextMenu* emptyMenu = jnew JXTextMenu(itsActionsMenu, kEmptyMenuCmd, menuBar); assert( emptyMenu != NULL ); JXMenu* prevMenu = itsActionsMenu; JIndex prevMenuIndex = kAdviceMenuCmd; for (i=1; i<=kAdviceMenuCount; i++) { JXTextMenu* adviceMenu = jnew JXTextMenu(prevMenu, prevMenuIndex, menuBar); assert( adviceMenu != NULL ); adviceMenu->SetMenuItems(kAdviceMenuStr[i-1]); adviceMenu->SetUpdateAction(JXMenu::kDisableNone); if (i == kAdviceBoldMenuIndex) { adviceMenu->SetItemFontStyle(2, JFontStyle(kJTrue, kJFalse, 0, kJFalse, GetColormap()->GetBlackColor())); } prevMenu = adviceMenu; prevMenuIndex = 2; } BuildXlsfontsMenu(itsActionsMenu, menuBar); // secret menus are a bad idea because the user can't find them! itsSecretMenu = jnew JXTextMenu("", this, kFixedLeft, kFixedTop, 0,0, 10,10); assert( itsSecretMenu != NULL ); itsSecretMenu->SetMenuItems(kSecretMenuStr); itsSecretMenu->SetUpdateAction(JXMenu::kDisableNone); itsSecretMenu->SetToHiddenPopupMenu(kJTrue); // will assert() otherwise itsSecretMenu->Hide(); ListenTo(itsSecretMenu); itsSecretSubmenu = jnew JXTextMenu(itsSecretMenu, kSecretSubmenuIndex, this); assert( itsSecretSubmenu != NULL ); itsSecretSubmenu->SetMenuItems(kSecretSubmenuStr); itsSecretSubmenu->SetUpdateAction(JXMenu::kDisableNone); // we don't ListenTo() it because it's only there for show // image from xpm itsXPMImage = jnew JXImage(GetDisplay(), JXPM(macapp_xpm)); assert( itsXPMImage != NULL ); // partial image from image itsPartialXPMImage = jnew JXImage(*itsXPMImage, JRect(5,5,14,16)); assert( itsPartialXPMImage != NULL ); // home symbol itsHomeImage = jnew JXImage(GetDisplay(), JXPM(home_xpm)); assert( itsHomeImage != NULL ); itsHomeRect = itsHomeImage->GetBounds(); itsHomeRect.Shift(120, 10); // buffer contents of Widget in JXImage itsImageBuffer = NULL; if (isImage) { CreateImageBuffer(); } // initial size SetBounds(400,400); // enclosed objects itsAnimButton = jnew JXTextButton("Start", this, JXWidget::kFixedLeft, JXWidget::kFixedTop, 37,175, 50,30); assert( itsAnimButton != NULL ); itsAnimButton->SetShortcuts("#A"); ListenTo(itsAnimButton); if (isMaster) { itsQuitButton = jnew JXTextButton(JGetString("Quit::TestWidget"), this, JXWidget::kFixedRight, JXWidget::kFixedBottom, x,y, 50,30); assert( itsQuitButton != NULL ); JXColormap* colormap = GetColormap(); itsQuitButton->CenterWithinEnclosure(kJTrue, kJTrue); itsQuitButton->SetFontStyle(JFontStyle(kJTrue, kJFalse, 0, kJFalse, colormap->GetRedColor())); itsQuitButton->SetNormalColor(colormap->GetCyanColor()); itsQuitButton->SetPushedColor(colormap->GetBlueColor()); ListenTo(itsQuitButton); } else { itsQuitButton = NULL; } ExpandToFitContent(); // drops on iconfied window JXWindowIcon* windowIcon; const JBoolean hasIconWindow = GetWindow()->GetIconWidget(&windowIcon); assert( hasIconWindow ); ListenTo(windowIcon); }
void TestWidget::DrawStuff ( JPainter& p ) { JIndex i; JXColormap* colormap = GetColormap(); p.SetPenColor(colormap->GetGreenColor()); JRect ellipseRect(100,50,150,300); p.Ellipse(ellipseRect); p.SetPenColor(colormap->GetBlackColor()); if (itsFillFlag) { p.SetFilling(kJTrue); } JRect ap = GetAperture(); p.Line(ap.topLeft(), ap.bottomRight()); p.Line(ap.topRight(), ap.bottomLeft()); p.SetLineWidth(2); p.SetFontName(JXGetTimesFontName()); p.SetFontSize(18); p.Image(*itsHomeImage, itsHomeImage->GetBounds(), itsHomeRect); its2Rect = JRect(150, 5, 200, 30); p.SetPenColor(colormap->GetRedColor()); p.Rect(its2Rect); p.SetFontStyle(colormap->GetRedColor()); p.String(its2Rect.topLeft(), "2", its2Rect.width(), JPainter::kHAlignCenter, its2Rect.height(), JPainter::kVAlignCenter); its3Rect = JRect(10, 150, 40, 200); p.SetPenColor(colormap->GetBlueColor()); p.Rect(its3Rect); p.SetFontStyle(colormap->GetBlueColor()); p.String(its3Rect.topLeft(), "3", its3Rect.width(), JPainter::kHAlignCenter, its3Rect.height(), JPainter::kVAlignCenter); p.SetLineWidth(1); p.SetFont(JGetDefaultFontName(), kJXDefaultFontSize, colormap->GetBlackColor()); p.ShiftOrigin(10,10); p.Point(0,0); for (i=1; i<=itsRandPointCount; i++) { p.Point(itsRNG.UniformLong(0,200), itsRNG.UniformLong(0,200)); } p.SetPenColor(colormap->GetRedColor()); p.Line(10,0, 0,10); p.SetPenColor(colormap->GetGreenColor()); p.LineTo(10,20); p.SetPenColor(colormap->GetBlueColor()); p.LineTo(0,30); p.ShiftOrigin(2,0); JPoint textPt(40,30); p.String( 0.0, textPt, "Hello"); p.String( 90.0, textPt, "Hello"); p.String(180.0, textPt, "Hello"); p.String(270.0, textPt, "Hello"); p.Rect(310, 70, 80, 80); p.String( 0.0, 310, 70, "Hello", 80, JPainter::kHAlignCenter, 80, JPainter::kVAlignCenter); p.String( 90.0, 310,150, "Hello", 80, JPainter::kHAlignCenter, 80, JPainter::kVAlignCenter); p.String(180.0, 390,150, "Hello", 80, JPainter::kHAlignCenter, 80, JPainter::kVAlignCenter); p.String(270.0, 390, 70, "Hello", 80, JPainter::kHAlignCenter, 80, JPainter::kVAlignCenter); p.Rect(200, 10, 100, 50); p.String(200, 10, "Hello", 100, JPainter::kHAlignLeft); p.String(200, 10+p.GetLineHeight(), "Hello", 100, JPainter::kHAlignCenter); p.String(200, 10+2*p.GetLineHeight(), "Hello", 100, JPainter::kHAlignRight); p.SetPenColor(colormap->GetYellowColor()); JRect r(0,11,80,91); p.Rect(r); r.Shrink(1,1); p.SetPenColor(colormap->GetBlueColor()); p.Ellipse(r); r.Shrink(1,1); p.SetPenColor(colormap->GetRedColor()); p.Arc(r, 270.0-45.0, -270.0); JPolygon poly; poly.AppendElement(JPoint(0,85)); poly.AppendElement(JPoint(10,85)); poly.AppendElement(JPoint(5,95)); p.Polygon(poly); p.Line(0,100, 2,98); p.LineTo(4,100); p.LineTo(2,102); p.LineTo(0,100); poly.SetElement(1, JPoint(0,5)); poly.SetElement(2, JPoint(2,0)); poly.SetElement(3, JPoint(4,5)); p.Polygon(2,105, poly); // test filling rule p.SetPenColor(colormap->GetRedColor()); p.SetFilling(kJTrue); JPolygon fillRulePoly; fillRulePoly.AppendElement(JPoint(175,45)); fillRulePoly.AppendElement(JPoint(165,65)); fillRulePoly.AppendElement(JPoint(190,50)); fillRulePoly.AppendElement(JPoint(160,50)); fillRulePoly.AppendElement(JPoint(185,65)); p.Polygon(fillRulePoly); p.SetFilling(kJFalse); // dashed lines p.DrawDashedLines(kJTrue); p.SetPenColor(colormap->GetBlackColor()); JArray<JSize> dashList; // pixel rulers dashList.AppendElement(1); dashList.AppendElement(1); p.SetDashList(dashList); p.Line(100,110, 200,110); p.Line(100,114, 200,114); p.Line(100,118, 200,118); dashList.SetElement(1, 2); // simple pattern dashList.SetElement(2, 3); p.SetDashList(dashList); p.Line(100,112, 200,112); p.SetFontStyle(JFontStyle(kJFalse, kJFalse, 1, kJFalse)); p.String(130,155, "underline without dashes"); p.SetDashList(dashList, 3); // test offset p.Line(100,116, 200,116); dashList.SetElement(1, 1); // example with odd # of values from X manuals dashList.SetElement(2, 2); dashList.AppendElement(3); p.SetDashList(dashList); p.Line(100,120, 200,120); dashList.SetElement(1, 5); // dash-dot pattern dashList.SetElement(2, 2); dashList.SetElement(3, 1); dashList.AppendElement(2); p.SetDashList(dashList); p.Line(100,122, 200,122); p.Ellipse(210,110, 20,20); p.DrawDashedLines(kJFalse); p.Ellipse(213,113, 14,14); p.Rect(207,107, 26,26); p.SetPenColor(colormap->GetYellowColor()); p.DrawDashedLines(kJTrue); p.Ellipse(213,113, 14,14); // animated colors p.SetFilling(kJTrue); JCoordinate x = 25; const JSize animColorCount = itsAnimColorList->GetElementCount(); for (i=1; i<=animColorCount; i++) { p.SetPenColor(itsAnimColorList->GetElement(i)); p.Rect(x, 150, 10, 10); x += 10; } // icons p.Image(*itsXPMImage, itsXPMImage->GetBounds(), 33,110); p.Image(*itsPartialXPMImage, itsXPMImage->GetBounds(), 50,121); // *NEVER* do this in your code! I do it here ONLY to test JXColormap. // (Besides, look at how messy it is!) unsigned long xPixel; if (colormap->CalcPreallocatedXPixel(62720, 56832, 45824, &xPixel)) { JXDisplay* display = GetDisplay(); Display* xdisplay = display->GetXDisplay(); GC gc = DefaultGC(xdisplay, display->GetScreen()); XSetForeground(xdisplay, gc, xPixel); XFillRectangle(xdisplay, (GetWindow())->GetXWindow(), gc, 110,40, 20,20); } }
void THXBaseConvDirector::BuildWindow() { // begin JXLayout JXWindow* window = new JXWindow(this, 300,130, ""); assert( window != NULL ); SetWindow(window); itsCloseButton = new JXTextButton("Close", window, JXWidget::kFixedRight, JXWidget::kFixedTop, 180,100, 60,20); assert( itsCloseButton != NULL ); itsCloseButton->SetShortcuts("#W^["); itsFromValue = new JXInputField(window, JXWidget::kHElastic, JXWidget::kFixedTop, 110,20, 70,20); assert( itsFromValue != NULL ); JXStaticText* obj1 = new JXStaticText("Convert from:", window, JXWidget::kFixedLeft, JXWidget::kFixedTop, 20,20, 90,20); assert( obj1 != NULL ); itsHelpButton = new JXTextButton("Help", window, JXWidget::kFixedLeft, JXWidget::kFixedTop, 60,100, 60,20); assert( itsHelpButton != NULL ); itsFromBase = new THXBaseConvMenu(window, JXWidget::kFixedRight, JXWidget::kFixedTop, 190,15, 90,30); assert( itsFromBase != NULL ); JXStaticText* obj2 = new JXStaticText("Result:", window, JXWidget::kFixedLeft, JXWidget::kFixedTop, 20,60, 90,20); assert( obj2 != NULL ); itsToBase = new THXBaseConvMenu(window, JXWidget::kFixedRight, JXWidget::kFixedTop, 190,55, 90,30); assert( itsToBase != NULL ); itsToValue = new JXStaticText("", kJFalse, kJTrue, NULL, window, JXWidget::kHElastic, JXWidget::kFixedTop, 110,60, 70,20); assert( itsToValue != NULL ); // end JXLayout window->SetTitle("Base Conversion"); window->SetWMClass(THXGetWMClassInstance(), THXGetBaseConvWindowClass()); window->LockCurrentMinSize(); window->SetCloseAction(JXWindow::kDeactivateDirector); window->ShouldFocusWhenShow(kJTrue); window->PlaceAsDialogWindow(); JXDisplay* display = GetDisplay(); JXImage* icon = new JXImage(display, display->GetColormap(), thx_base_conv_window); assert( icon != NULL ); window->SetIcon(icon); itsFromValue->ShouldBroadcastAllTextChanged(kJTrue); // want every keypress ListenTo(itsFromValue); ListenTo(itsFromBase); ListenTo(itsToBase); ListenTo(itsCloseButton); ListenTo(itsHelpButton); }
JBoolean JXApplication::HandleOneEventForWindow ( JXWindow* window, const JBoolean origAllowSleep ) { const JBoolean origHadBlockingWindowFlag = itsHadBlockingWindowFlag; itsHasBlockingWindowFlag = kJTrue; itsHadBlockingWindowFlag = kJFalse; // req'd by JXWindow if (itsIdleTaskStack->IsEmpty()) { PushIdleTaskStack(); } UpdateCurrentTime(); const JBoolean allowSleep = JI2B(origAllowSleep && HandleCustomEventWhileBlocking()); UpdateCurrentTime(); JBoolean windowHasEvents = kJFalse; const JXDisplay* uiDisplay = window->GetDisplay(); Window eventWindow [ kEventWindowCount ]; eventWindow[0] = window->GetXWindow(); JPtrArrayIterator<JXDisplay> iter(itsDisplayList); JXDisplay* display; JIndex displayIndex = 0; while (iter.Next(&display)) { JXMenuManager* menuMgr = display->GetMenuManager(); if (!origHadBlockingWindowFlag) { menuMgr->CloseCurrentMenus(); } JXWindow* mouseContainer; displayIndex++; itsCurrDisplayIndex = displayIndex; // itsCurrDisplayIndex might change during event if (XPending(*display) != 0) { // get mouse and keyboard grabbers -- for menus inside blocking window eventWindow[1] = eventWindow[2] = None; JXWindow* grabber; if (display == uiDisplay && display->GetMouseGrabber(&grabber) && menuMgr->IsMenuForWindow(grabber, window)) { eventWindow[1] = grabber->GetXWindow(); } if (display == uiDisplay && display->GetKeyboardGrabber(&grabber) && menuMgr->IsMenuForWindow(grabber, window)) { eventWindow[2] = grabber->GetXWindow(); } // process one event XEvent xEvent; if (display == uiDisplay && XCheckIfEvent(*display, &xEvent, GetNextWindowEvent, reinterpret_cast<char*>(eventWindow))) { windowHasEvents = kJTrue; if (xEvent.type != MotionNotify) { itsLastIdleTime = itsCurrentTime; } display->HandleEvent(xEvent, itsCurrentTime); } else if (XCheckIfEvent(*display, &xEvent, GetNextBkgdEvent, NULL)) { display->HandleEvent(xEvent, itsCurrentTime); } else if (display == uiDisplay && display->GetMouseContainer(&mouseContainer) && mouseContainer == window) { display->Idle(itsCurrentTime); } else { display->Update(); } // discard mouse and keyboard events DiscardEventInfo discardInfo(display, NULL); if (display == uiDisplay) { discardInfo.eventWindow = eventWindow; } while (XCheckIfEvent(*display, &xEvent, DiscardNextEvent, reinterpret_cast<char*>(&discardInfo))) { }; } else if (display == uiDisplay && display->GetMouseContainer(&mouseContainer) && mouseContainer == window) { display->Idle(itsCurrentTime); } else { display->Update(); } } PerformTasks(windowHasEvents, allowSleep); itsHasBlockingWindowFlag = kJFalse; itsHadBlockingWindowFlag = kJTrue; return windowHasEvents; }
void TestDirector::BuildWindow ( const JBoolean isMaster, const JBoolean bufferTestWidget, const JBoolean testWidgetIsImage ) { JXDisplay* display = (JXGetApplication())->GetCurrentDisplay(); JXColormap* colormap = display->GetColormap(); // begin JXLayout JXWindow* window = new JXWindow(this, 400,330, ""); assert( window != NULL ); JXMenuBar* menuBar = new JXMenuBar(window, JXWidget::kHElastic, JXWidget::kFixedTop, 0,0, 400,30); assert( menuBar != NULL ); JXScrollbarSet* scrollbarSet = new JXScrollbarSet(window, JXWidget::kHElastic, JXWidget::kVElastic, 0,30, 400,300); assert( scrollbarSet != NULL ); // end JXLayout window->SetTitle("Test Director"); window->SetWMClass("testjx", "TestDirector"); window->SetMinSize(150,150); if (isMaster) { window->SetCloseAction(JXWindow::kQuitApp); } else { window->SetCloseAction(JXWindow::kCloseDisplay); } itsAnimIconTask = new AnimateWindowIconTask(GetWindow()); assert( itsAnimIconTask != NULL ); ListenTo(window); // for icon animation // menus JXImage* aboutTitleImage = new JXImage(display, kSmileyBitmap[ kHappySmileyIndex ], colormap->GetRedColor()); assert( aboutTitleImage != NULL ); itsAboutMenu = menuBar->AppendTextMenu(aboutTitleImage, kJTrue); itsAboutMenu->SetShortcuts(kAboutMenuShortcuts); itsAboutMenu->SetMenuItems(kAboutMenuStr, "TestDirector"); itsAboutMenu->SetUpdateAction(JXMenu::kDisableNone); ListenTo(itsAboutMenu); itsAnimHelpTask = new AnimateHelpMenuTask(itsAboutMenu, kHelpCmd); assert( itsAnimHelpTask != NULL ); itsPrintPSMenu = new JXTextMenu(itsAboutMenu, kPrintPSMenuCmd, menuBar); assert( itsPrintPSMenu != NULL ); itsPrintPSMenu->SetMenuItems(kPrintPSMenuStr); itsPrintPSMenu->SetUpdateAction(JXMenu::kDisableNone); ListenTo(itsPrintPSMenu); itsTestMenu = menuBar->AppendTextMenu(kTestMenuTitleStr); itsTestMenu->SetMenuItems(kTestMenuStr); itsTestMenu->SetUpdateAction(JXMenu::kDisableNone); ListenTo(itsTestMenu); itsUNMenu = new JXTextMenu(itsTestMenu, kTestUserNotifyMenuCmd, menuBar); assert( itsUNMenu != NULL ); itsUNMenu->SetMenuItems(kUserNotificationMenuStr); itsUNMenu->SetUpdateAction(JXMenu::kDisableNone); ListenTo(itsUNMenu); itsCSFMenu = new JXTextMenu(itsTestMenu, kTestChooseSaveFileMenuCmd, menuBar); assert( itsCSFMenu != NULL ); itsCSFMenu->SetMenuItems(kChooseSaveFileMenuStr); itsCSFMenu->SetUpdateAction(JXMenu::kDisableNone); ListenTo(itsCSFMenu); itsPGMenu = new JXTextMenu(itsTestMenu, kTestPGMenuCmd, menuBar); assert( itsPGMenu != NULL ); itsPGMenu->SetMenuItems(kProgressDisplayMenuStr); itsPGMenu->SetUpdateAction(JXMenu::kDisableNone); ListenTo(itsPGMenu); if (isMaster) { itsDisplayMenu = new JXDisplayMenu(kDisplayMenuName, menuBar, JXWidget::kFixedLeft, JXWidget::kFixedTop, 0,0, 10,10); assert( itsDisplayMenu != NULL ); menuBar->AppendMenu(itsDisplayMenu); } else { itsDisplayMenu = NULL; } itsWidget = new TestWidget(isMaster, testWidgetIsImage, menuBar, scrollbarSet, scrollbarSet->GetScrollEnclosure(), JXWidget::kHElastic, JXWidget::kVElastic, 0,0, 10,10); assert( itsWidget != NULL ); itsWidget->FitToEnclosure(kJTrue, kJTrue); itsWidget->SetSingleFocusWidget(); BuildIconMenus(window, menuBar); // do this -after- constructing JXScrollableWidget (GetWindow())->BufferDrawing(bufferTestWidget); }
JBoolean JXApplication::HandleOneBusyEvent ( const JBoolean origAllowSleep ) { itsHadBlockingWindowFlag = kJFalse; UpdateCurrentTime(); JBoolean cancelRequest = kJFalse; JPtrArrayIterator<JXDisplay> iter(itsDisplayList); JXDisplay* display; JIndex displayIndex = 0; while (iter.Next(&display)) { displayIndex++; itsCurrDisplayIndex = displayIndex; // itsCurrDisplayIndex might change during event if (XPending(*display) != 0) { // look for update events XEvent xEvent; if (XCheckIfEvent(*display, &xEvent, GetNextBusyEvent, NULL)) { display->HandleEvent(xEvent, itsCurrentTime); } // discard mouse and keyboard events DiscardEventInfo discardInfo(display, NULL); while (XCheckIfEvent(*display, &xEvent, DiscardNextEvent, reinterpret_cast<char*>(&discardInfo))) { // Look for key press cancel if (xEvent.type == KeyPress) { JCharacter buffer[10]; KeySym keySym; JSize charCount = XLookupString(const_cast<XKeyEvent*>(&(xEvent.xkey)), buffer, 10, &keySym, NULL); if (keySym == XK_Escape) { cancelRequest = kJTrue; } } } } { // Do display idle but don't allow it to dispatch the mouse // as we are likely to have the busy cursor currently displayed JXWindow* container = NULL; display->GetMouseContainer(&container); display->SetMouseContainer(NULL); display->Idle(itsCurrentTime); display->SetMouseContainer(container); } } // Perform permanent & urgent tasks //PerformPermanentTasks(); //PerformUrgentTasks(); itsHadBlockingWindowFlag = kJTrue; return cancelRequest; }
JBoolean JXApplication::HandleOneEventForWindow ( JXWindow* window, const JBoolean origAllowSleep, const JBoolean do_tasks ) { const JBoolean origHadBlockingWindowFlag = itsHadBlockingWindowFlag; itsHasBlockingWindowFlag = kJTrue; itsHadBlockingWindowFlag = kJFalse; // req'd by JXWindow if (itsIdleTaskStack->IsEmpty()) { PushIdleTaskStack(); } UpdateCurrentTime(); const JBoolean allowSleep = JI2B(origAllowSleep && HandleCustomEventWhileBlocking()); UpdateCurrentTime(); JBoolean windowHasEvents = kJFalse; const JXDisplay* uiDisplay = window->GetDisplay(); Window eventWindow [ kEventWindowCount ]; eventWindow[0] = window->GetXWindow(); JPtrArrayIterator<JXDisplay> iter(itsDisplayList); JXDisplay* display; JIndex displayIndex = 0; while (iter.Next(&display)) { JXMenuManager* menuMgr = display->GetMenuManager(); if (!origHadBlockingWindowFlag) { menuMgr->CloseCurrentMenus(); } JXWindow* mouseContainer; displayIndex++; itsCurrDisplayIndex = displayIndex; // itsCurrDisplayIndex might change during event if (XPending(*display) != 0) { // get mouse and keyboard grabbers -- for menus inside blocking window eventWindow[1] = eventWindow[2] = None; JXWindow* grabber; if (display == uiDisplay && display->GetMouseGrabber(&grabber) && menuMgr->IsMenuForWindow(grabber, window)) { eventWindow[1] = grabber->GetXWindow(); } if (display == uiDisplay && display->GetKeyboardGrabber(&grabber) && menuMgr->IsMenuForWindow(grabber, window)) { eventWindow[2] = grabber->GetXWindow(); } // process one event XEvent xEvent; if (display == uiDisplay && XCheckIfEvent(*display, &xEvent, GetNextWindowEvent, reinterpret_cast<char*>(eventWindow))) { windowHasEvents = kJTrue; if (xEvent.type != MotionNotify) { itsLastIdleTime = itsCurrentTime; } display->HandleEvent(xEvent, itsCurrentTime); } #if 0 // cd: background event check is now done as part of window event check // to give better update responsiveness when dragging a window else if (XCheckIfEvent(*display, &xEvent, GetNextBkgdEvent, NULL)) { display->HandleEvent(xEvent, itsCurrentTime); } #endif else if (display == uiDisplay && display->GetMouseContainer(&mouseContainer) && mouseContainer == window) { display->Idle(itsCurrentTime); } else { display->Update(); } // discard mouse and keyboard events DiscardEventInfo discardInfo(display, NULL); if (display == uiDisplay) { discardInfo.eventWindow = eventWindow; } while (XCheckIfEvent(*display, &xEvent, DiscardNextEvent, reinterpret_cast<char*>(&discardInfo))) { }; } else if (display == uiDisplay && display->GetMouseContainer(&mouseContainer) && mouseContainer == window) { display->Idle(itsCurrentTime); } else { display->Update(); } } // Perform idle tasks when we don't receive any events and // during long intervals of "mouse moved". if (do_tasks) { if (!windowHasEvents) { PerformPermanentTasks(); PerformIdleTasks(); itsLastIdleTime = itsCurrentTime; PerformUrgentTasks(); if (allowSleep) { JWait(itsMaxSleepTime / 1000.0); } } else if (windowHasEvents && itsCurrentTime - itsLastIdleTime > itsMaxSleepTime) { PerformPermanentTasks(); PerformIdleTasks(); itsLastIdleTime = itsCurrentTime; PerformUrgentTasks(); } else { PerformPermanentTasks(); PerformUrgentTasks(); } } itsHasBlockingWindowFlag = kJFalse; itsHadBlockingWindowFlag = kJTrue; return windowHasEvents; }
void JXApplication::HandleOneEvent() { itsHadBlockingWindowFlag = kJFalse; UpdateCurrentTime(); const JBoolean allowSleep = HandleCustomEvent(); UpdateCurrentTime(); JBoolean hasEvents = kJFalse; JPtrArrayIterator<JXDisplay> iter(itsDisplayList); JXDisplay* display; JIndex displayIndex = 0; while (iter.Next(&display)) { displayIndex++; itsCurrDisplayIndex = displayIndex; // itsCurrDisplayIndex might change during event if (XPending(*display) != 0) { hasEvents = kJTrue; // get the next event XEvent xEvent; XNextEvent(*display, &xEvent); if (xEvent.type != MotionNotify) { itsLastIdleTime = itsCurrentTime; } // dispatch the event display->HandleEvent(xEvent, itsCurrentTime); } else { display->Idle(itsCurrentTime); } } PopAllIdleTaskStack(); // Perform idle tasks when we don't receive any events and // during long intervals of "mouse moved". if (!hasEvents) { PerformPermanentTasks(); PerformIdleTasks(); itsLastIdleTime = itsCurrentTime; PerformUrgentTasks(); if (allowSleep) { JWait(itsMaxSleepTime / 1000.0); } } else if (hasEvents && itsCurrentTime - itsLastIdleTime > itsMaxSleepTime) { PerformPermanentTasks(); PerformIdleTasks(); itsLastIdleTime = itsCurrentTime; PerformUrgentTasks(); } else { PerformPermanentTasks(); PerformUrgentTasks(); } }
JBoolean JXImageSelection::GetImage ( JXSelectionManager* selMgr, const Atom selectionName, const Time time, JXColormap* colormap, JXImage** image, const JBoolean allowApproxColors ) { JXDisplay* display = colormap->GetDisplay(); const Atom xpmXAtom = display->RegisterXAtom(kXPMXAtomName); const Atom gifXAtom = display->RegisterXAtom(kGIFXAtomName); const Atom pngXAtom = display->RegisterXAtom(kPNGXAtomName); const Atom jpegXAtom = display->RegisterXAtom(kJPEGXAtomName); JArray<Atom> typeList; if (selMgr->GetAvailableTypes(selectionName, time, &typeList)) { JBoolean xpm=kJFalse, gif=kJFalse, png=kJFalse, jpeg=kJFalse; const JSize count = typeList.GetElementCount(); for (JIndex i=1; i<=count; i++) { const Atom type = typeList.GetElement(i); xpm = JI2B( xpm || type == xpmXAtom ); gif = JI2B( gif || type == gifXAtom ); png = JI2B( png || type == pngXAtom ); jpeg = JI2B( jpeg || type == jpegXAtom ); } while (xpm || gif || png || jpeg) { Atom type = None; if (png) { png = kJFalse; type = pngXAtom; } else if (gif) { gif = kJFalse; type = gifXAtom; } else if (xpm) { xpm = kJFalse; type = xpmXAtom; } else if (jpeg) // JPEG is lossy { jpeg = kJFalse; type = jpegXAtom; } Atom returnType; unsigned char* data; JSize dataLength; JXSelectionManager::DeleteMethod delMethod; JString fileName; if (selMgr->GetData(selectionName, time, type, &returnType, &data, &dataLength, &delMethod) && (JCreateTempFile(&fileName)).OK()) { ofstream output(fileName); output.write((char*) data, dataLength); output.close(); selMgr->DeleteData(&data, delMethod); const JError err = JXImage::CreateFromFile(display, colormap, fileName, image, allowApproxColors); JRemoveFile(fileName); if (err.OK()) { return kJTrue; } } } } *image = NULL; return kJFalse; }
void WizChatDirector::BuildWindow() { // begin JXLayout JXWindow* window = new JXWindow(this, 600,250, ""); assert( window != NULL ); JXMenuBar* menuBar = new JXMenuBar(window, JXWidget::kHElastic, JXWidget::kFixedTop, 0,0, 600,30); assert( menuBar != NULL ); JXScrollbarSet* scrollbarSet = new JXScrollbarSet(window, JXWidget::kHElastic, JXWidget::kVElastic, 0,30, 600,180); assert( scrollbarSet != NULL ); itsChatInput = new WizChatInput(window, JXWidget::kHElastic, JXWidget::kFixedBottom, 90,210, 510,40); assert( itsChatInput != NULL ); itsChatShortcutMenu = new WizChatShortcutMenu(itsChatInput, window, JXWidget::kFixedLeft, JXWidget::kFixedBottom, 0,210, 90,20); assert( itsChatShortcutMenu != NULL ); itsChatTargetMenu = new WizChatTargetMenu(itsChatInput, itsChatShortcutMenu, window, JXWidget::kFixedLeft, JXWidget::kFixedBottom, 0,230, 90,20); assert( itsChatTargetMenu != NULL ); // end JXLayout window->SetTitle("Chat"); window->SetMinSize(150, 150); window->SetWMClass(WizGetWMClassInstance(), WizGetChatWindowClass()); JXDisplay* display = GetDisplay(); JXImage* icon = new JXImage(display, display->GetColormap(), jx_un_message); assert( icon != NULL ); window->SetIcon(icon); itsMessageDisplay = new JXStaticText("", kJTrue, kJTrue, scrollbarSet, scrollbarSet->GetScrollEnclosure(), JXWidget::kHElastic, JXWidget::kVElastic, 0,0, 100,100); assert( itsMessageDisplay != NULL ); itsMessageDisplay->FitToEnclosure(); itsChatInput->SetShortcutMenu(itsChatShortcutMenu); ListenTo(itsChatTargetMenu); itsActionsMenu = menuBar->AppendTextMenu(kActionsMenuTitleStr); itsActionsMenu->SetMenuItems(kActionsMenuStr); itsActionsMenu->SetUpdateAction(JXMenu::kDisableNone); ListenTo(itsActionsMenu); itsMessageDisplay->AppendEditMenu(menuBar); itsChatInput->ShareEditMenu(itsMessageDisplay); itsPrefsMenu = menuBar->AppendTextMenu(kPrefsMenuTitleStr); itsPrefsMenu->SetMenuItems(kPrefsMenuStr); itsPrefsMenu->SetUpdateAction(JXMenu::kDisableNone); ListenTo(itsPrefsMenu); itsHelpMenu = menuBar->AppendTextMenu(kHelpMenuTitleStr); itsHelpMenu->SetMenuItems(kHelpMenuStr); itsHelpMenu->SetUpdateAction(JXMenu::kDisableNone); ListenTo(itsHelpMenu); }