📄 i_notebk.cpp
字号:
} else tError = ZAF_ERROR_INVALID; return (tError);}bool ZafNotebook::SetPageDisabled(int page, bool setDisabled){ ZafWindowObject *tab = tabControl->Get(page); return (tab ? tab->SetDisabled(setDisabled) : false);}// ----- OS Specific Functions ----------------------------------------------void ZafNotebook::OSDestroy(void){ // Destroy the notebook tabs. tabControl->Destroy(); // Let the base class process. ZafWindow::OSDestroy();}void ZafNotebook::OSRegisterObject(void){ ZafWindow::OSRegisterObject();}OSWindowID ZafNotebook::OSScreenID(ZafScreenIDType type) const{ return (ZafWindow::OSScreenID(type));}// ----- ZafNotebookTab -------------------------------------------------------ZafPaletteMap ZAF_FARDATA tabPaletteMap[] ={ { ZAF_PM_LIGHT_SHADOW, ZAF_PM_ANY_STATE, { ZAF_LINE_SOLID, ZAF_PTN_SOLID_FILL, ZAF_CLR_LIGHTGRAY, ZAF_CLR_WHITE, ZAF_MONO_BLACK, ZAF_MONO_WHITE, ZAF_FNT_SMALL } }, { ZAF_PM_DARK_SHADOW, ZAF_PM_ANY_STATE, { ZAF_LINE_SOLID, ZAF_PTN_SOLID_FILL, ZAF_CLR_DARKGRAY, ZAF_CLR_BLACK, ZAF_MONO_BLACK, ZAF_MONO_WHITE, ZAF_FNT_SMALL } }, { ZAF_PM_NONE, 0, { 0, 0, 0, 0, 0, 0, 0, 0 } }};ZafNotebookTab::ZafNotebookTab(const ZafIChar *text) : ZafButton(0, 0, 0, 1, text){ SetSelectOnDownClick(true); SetHzJustify(ZAF_HZ_CENTER); SetOSDraw(false); SetNoncurrent(true); SetDepth(1); SetUserPaletteData(new ZafPaletteData(tabPaletteMap, true)); SetSystemObject(false); SetFont(ZAF_FNT_PARENT);}ZafNotebookTab::ZafNotebookTab(const ZafNotebookTab ©) : ZafButton(copy){}#if defined(ZAF_DEFAULT_DRAW)ZafEventType ZafNotebookTab::ClassDraw(const ZafEventStruct &event, ZafEventType ccode){ // Compute the actual draw region. ZafRegionStruct drawRegion = BeginDraw(); // Don't draw over the bottom shadow (the current page's top shadow). if (((ZafNotebookTabControl *)parent)->currentTab != this) drawRegion.bottom -= ZAF_BORDER_SIZE; DrawBackground(drawRegion, ccode); DrawShadow(drawRegion, 0, ccode); const ZafIChar *text = Text(); display->SetPalette(LogicalPalette(ZAF_PM_TEXT, PaletteState())); display->Text(drawRegion, text, -1, ZAF_HZ_CENTER, vtJustify, hotKeyIndex); EndDraw(); return (ccode);}ZafEventType ZafNotebookTab::DrawShadow(ZafRegionStruct ®ion, int, ZafEventType ccode){ ZafPaletteStruct lightShadow; ZafPaletteStruct darkShadow; ZafPaletteStruct whiteShadow; ZafPaletteStruct blackShadow; ShadowPalettes(ZAF_PM_ANY_STATE, &lightShadow, &darkShadow, &whiteShadow, &blackShadow); // Left shadow area. ZafCoordinate point[6]; point[0] = region.left; point[1] = region.bottom; point[2] = region.left; point[3] = region.top + chisel; point[4] = region.left + chisel; point[5] = region.top; display->SetPalette(whiteShadow); display->Line(region.left, region.top + chisel, region.left, region.bottom); display->Line(region.left + 1, region.top + chisel - 1, region.left + 1, region.bottom); display->Line(region.left + chisel, region.top + 1, region.right - chisel, region.top + 1); // Top shadow area. display->Line(region.left + chisel, region.top, region.right - chisel, region.top); // Right shadow area. point[0] = region.right; point[1] = region.bottom; point[2] = region.right; point[3] = region.top + chisel; point[4] = region.right - chisel + 1; point[5] = region.top + 1; display->SetPalette(blackShadow); display->Polygon(3, point); point[0] = region.right - 1; point[1] = region.bottom; point[2] = region.right - 1; point[3] = region.top + chisel; point[4] = region.right - chisel + 1; point[5] = region.top + 2; display->SetPalette(darkShadow); display->Polygon(3, point); region.left++; region.top++; region.right -= ZAF_BORDER_SIZE; return (ccode);}#endifZafEventType ZafNotebookTab::Event(const ZafEventStruct &event){ ZafEventType ccode = LogicalEvent(event); // Check for zinc events. switch (ccode) { // ----- Actions ----- case L_SELECT: { // Change the page. ZafNotebook *parentNotebook = DynamicPtrCast(parent->parent, ZafNotebook); if (parentNotebook) parentNotebook->SetCurrentPage(ListIndex()); } break; case S_COMPUTE_SIZE: // Calculate width according to text. ZafNotebookTabControl will // set height and position. ZafWindowObject::Event(event); display->SetFont(LogicalPalette(ZAF_PM_TEXT, ZAF_PM_ANY_STATE).font); zafRegion.left = 0; zafRegion.right = display->TextSize(Text()).Width() - 1 + 2 * display->cellWidth; break; // ----- Unknown or error messages ----- default: ccode = ZafButton::Event(event); break; } // Return the control code. return (ccode);}// ----- ZafNotebookTabControl ---------------------------------------------------ZafNotebookTabControl::ZafNotebookTabControl(void) : ZafWindow(0, 0, 10, 1), currentTab(ZAF_NULLP(ZafWindowObject)), firstVisible(ZAF_NULLP(ZafWindowObject)){ SetMoveable(false); SetNoncurrent(true); SetRegionType(ZAF_AVAILABLE_REGION); SetSizeable(false); SetSupportObject(true); SetFont(ZAF_FNT_PARENT); SetTextColor(ZAF_CLR_PARENT); SetBackgroundColor(ZAF_CLR_PARENT); Add(new ZafNotebookScrollArrows);}ZafNotebookTabControl::ZafNotebookTabControl(const ZafNotebookTabControl ©) : ZafWindow(copy){ firstVisible = First(); SetCurrentTab(firstVisible);}ZafNotebookTabControl::~ZafNotebookTabControl(void){}ZafWindowObject *ZafNotebookTabControl::Add(ZafWindowObject *object, ZafWindowObject *position){ bool saveUpdate = automaticUpdate; SetAutomaticUpdate(false); ZafWindowObject *retVal = ZafWindow::Add(object, position); if (screenID) Event(N_SIZE); SetAutomaticUpdate(saveUpdate); return (retVal);}ZafPositionStruct ZafNotebookTabControl::ConvertToOSPosition(const ZafWindowObject *object, const ZafPositionStruct *zafPosition) const{ ZafPositionStruct osPosition = ZafWindow::ConvertToOSPosition(object, zafPosition); if (!object->SupportObject()) { if (!firstVisible) ; else if (firstVisible == currentTab) osPosition.column -= firstVisible->zafRegion.left; else osPosition.column -= firstVisible->zafRegion.left - ZafNotebookTab::chisel; } return (osPosition);}ZafPositionStruct ZafNotebookTabControl::ConvertToZafPosition(const ZafWindowObject *object, const ZafPositionStruct *osPosition) const{ ZafPositionStruct zafPosition = ZafWindow::ConvertToZafPosition(object, osPosition); if (!object->SupportObject()) { if (!firstVisible) ; else if (firstVisible == currentTab) zafPosition.column += firstVisible->zafRegion.left; else zafPosition.column += firstVisible->zafRegion.left - ZafNotebookTab::chisel; } return (zafPosition);}ZafEventType ZafNotebookTabControl::DispatchMouseEvent(const ZafEventStruct &event){ return (ZafWindowObject::DispatchMouseEvent(event));}#if defined(ZAF_DEFAULT_DRAW)ZafEventType ZafNotebookTabControl::ClassDraw(const ZafEventStruct &event, ZafEventType ccode){ // Draw the background. ZafWindow::ClassDraw(event, ccode); // Compute the actual draw region. ZafRegionStruct drawRegion = BeginDraw(); // Draw the shadow at top of page (runs along bottom of tab control). ZafPaletteStruct lightShadow; ZafPaletteStruct whiteShadow; ShadowPalettes(ZAF_PM_ANY_STATE, &lightShadow, ZAF_NULLP(ZafPaletteStruct), &whiteShadow); display->SetPalette(whiteShadow); if (currentTab) { ZafRegionStruct curObjectRegion = currentTab->zafRegion; int scrollOffset = 0; if (firstVisible) scrollOffset = (firstVisible == currentTab ? firstVisible->zafRegion.left : firstVisible->zafRegion.left - ZafNotebookTab::chisel);// curObjectRegion.HzShift(-scrollOffset); display->Line(drawRegion.left, drawRegion.bottom, curObjectRegion.left, drawRegion.bottom); display->Line(curObjectRegion.right - 2, drawRegion.bottom, drawRegion.right, drawRegion.bottom); display->SetPalette(lightShadow); display->Line(curObjectRegion.left + 1, drawRegion.bottom, curObjectRegion.right - 2, drawRegion.bottom); } else display->Line(drawRegion.left, drawRegion.bottom, drawRegion.right, drawRegion.bottom); EndDraw(); return (ccode);}#endifZafEventType ZafNotebookTabControl::Event(const ZafEventStruct &event){ ZafNotebook *parentNBook = DynamicPtrCast(parent, ZafNotebook); // Switch on the event type. ZafEventType ccode = LogicalEvent(event); switch (ccode) { case S_COMPUTE_SIZE: ZafWindow::Event(event); zafRegion.bottom = zafRegion.top + parentNBook->TabHeight() + 1; break; case N_SIZE: { // Compute the default tab sizes. int tabHeight = parentNBook->TabHeight(); int tabWidth = parentNBook->TabWidth(); int totalTabWidth = 0; ZafWindowObject *object; for (object = First(); object; object = object->Next()) { object->Event(S_COMPUTE_SIZE); ZafRegionStruct newRegion; int width = tabWidth ? tabWidth : object->zafRegion.Width(); newRegion.top = ZafNotebookTab::chisel; newRegion.bottom = tabHeight; if (object->Previous()) newRegion.left = object->Previous()->zafRegion.right + 1 - (object->Previous() == currentTab ? ZafNotebookTab::chisel : 0); else newRegion.left = ZafNotebookTab::chisel; newRegion.right = newRegion.left + width - 1; if (object == currentTab) { newRegion.left -= ZafNotebookTab::chisel; newRegion.top -= ZafNotebookTab::chisel; newRegion.right += ZafNotebookTab::chisel; } newRegion.coordinateType = object->zafRegion.coordinateType; object->SetRegion(newRegion); object->OSSize(); totalTabWidth += object->zafRegion.Width(); } // Don't show the tab scrollers if not needed. ZafWindowObject *scrollArrows = (ZafWindowObject *)support.First(); bool showScrollArrows = (totalTabWidth >= zafRegion.Width()) ? true : false; if (!showScrollArrows && firstVisible != First()) { OSInvalidateRegion(0); firstVisible = First(); } scrollArrows->SetVisible(showScrollArrows); } break; case L_BEGIN_SELECT: case L_CONTINUE_SELECT: case L_END_SELECT: { // If the mouse is over the client region, let the current page process. if (clientRegion.Overlap(event.position)) { // Shift region so we can display what is in view. ZafPositionStruct scrolledMousePosition = event.position; ZafWindowObject *object; for (object = Last(); object && !object->zafRegion.Overlap(scrolledMousePosition); object = object->Previous()) ; // Do nothing. // object points to overlapped object. if (object) object->Event(event); } else if (SupportFirst()) SupportFirst()->Event(event); } break; case S_HSCROLL: { int offset = 0; if (event.scroll.delta < 0) { if (firstVisible && firstVisible->Previous()) { firstVisible = firstVisible->Previous(); offset = firstVisible->zafRegion.Width(); } } else { if (firstVisible && firstVisible->Next()) { offset = -firstVisible->zafRegion.Width(); firstVisible = firstVisible->Next(); } } if (offset) { for (ZafWindowObject *object = First(); object; object = object->Next()) { object->zafRegion.HzShift(offset); object->SetRegion(object->zafRegion); object->OSSize(); } OSInvalidateRegion(&clientRegion, false, false); } } break; default: ccode = ZafWindow::Event(event); break; } return (ccode);}ZafRegionStruct ZafNotebookTabControl::MaxRegion(ZafWindowObject *object, ZafVtJustify vWeight, ZafHzJustify hWeight){ // Check for existing OS region. ZafRegionStruct region = ZafWindow::MaxRegion(object, vWeight, hWeight); // Getting client region. Save room for shadow along top of notebook pages. if (!object || object == this || !object->SupportObject()) // scroll arrows region.bottom--; return (region);}int ZafNotebookTabControl::SetCurrentTab(int setCurrentTab){ // Set new tab current. ZafWindowObject *oldCurrent = currentTab; currentTab = DynamicPtrCast(Get(setCurrentTab), ZafWindowObject); if (!parent || !parent->screenID) { firstVisible = currentTab; return (setCurrentTab); } // Find scroll offset to draw proper area of tab control. int scrollOffset = firstVisible->zafRegion.left; if (currentTab->zafRegion.left < firstVisible->zafRegion.left) { // New current tab is off left edge. firstVisible = currentTab; } else if (currentTab->zafRegion.right - scrollOffset > clientRegion.right) { // New current tab is off right edge. while (currentTab->zafRegion.right - scrollOffset > clientRegion.right && firstVisible != Last()) { firstVisible = firstVisible->Next(); if (!firstVisible) firstVisible = Last(); scrollOffset = firstVisible->zafRegion.left; } } // Prevent tab control from updating until we're done switching tabs. SetAutomaticUpdate(false); // Update previously current tab's region. if (oldCurrent) { ZafRegionStruct newRegion = oldCurrent->zafRegion; newRegion.left += ZafNotebookTab::chisel; newRegion.top += ZafNotebookTab::chisel; newRegion.right -= ZafNotebookTab::chisel; oldCurrent->SetRegion(newRegion); oldCurrent->OSSize(); } // Update the new tab's region. ZafRegionStruct newRegion = currentTab->zafRegion; newRegion.left -= ZafNotebookTab::chisel; newRegion.top -= ZafNotebookTab::chisel; newRegion.right += ZafNotebookTab::chisel; currentTab->SetRegion(newRegion); currentTab->OSSize(); // Draw the tabs.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -