📄 i_notebk.cpp
字号:
// Zinc Application Framework - I_NOTEBK.CPP// Copyright (c) 1990-1998 Zinc Software, Inc.// Copyright (c) 1999-2003 Wind River Systems, Inc./*modification history--------------------01w,19jun03,jlb Fix SPR 70134 - Setting font does not adjust tabs01v,07may01,wdf Changed copyright date.01u,11dec00,bbj Fix SPR 62156--clipping not working properly01t,30nov00,wdf Fixed SPR# 62152. Made modifications to OSInvalidateRegion().01s,23oct00,wdf Changed copyright date.01r,19oct00,bbj distinguish between visible and dirty region clipping01q,21sep00,bbj Add ZafEventStruct parm to OSUpdateRegions to distinguish between frame and client updates01p,30aug00,bbj Fix drawing problem01o,21jul00,bbj Switch to using UGL windows01n,06jul00,bbj reentrancy protection under ZAF_RTOS vs. ZAF_REENTRANT01m,23may00,bbj DrawRegion changes01l,04apr00,jom Remove redundant editMode code01k,14mar00,jom Fix for moving modify code to a listener01j,24feb00,wdf Added code to Event() function to call event listeners.01i,14feb00,jom Remove assumptions about window decorations01h,09feb00,bbj Remove parm in call to SetDrawRegions01g,28jan00,wdf Made changes for drawhook.01f,18oct99,jom Fix FindMouseObject to give more control to the overlapped object01e,24sep99,bbj Add MT protection for drawing01d,21sep99,bbj Interop--switch to EventManager(), WindowManager() accessors01c,19aug99,bbj Add multithread protection01b,03aug99,wdf The ZafNotebookTabControl needs to have its font, text, background set to that of the parent so it will reflect changes made to the notebook.01a,27jul99,wdf liminated commented and redundent code, unnecassary functions and #defines*/#include <time.h>#include <zinc/generic/i_notebk.hpp>#include <zinc/z_app.hpp>#define USE_RAW_KEYS#include <zinc/z_keymap.hpp>#include <zinc/z_mouse2.hpp>#include <zinc/z_string.hpp>#include <zinc/z_title.hpp>#include <zinc/z_timer.hpp>#include <zinc/z_utils.hpp>// ----- ZafNotebook -------------------------------------------------------ZafWindowObject *ZafNotebook::Add(ZafWindowObject *object, ZafWindowObject *position){ // Modify the addition to be the notebook page, not its tab. if (!object) return (ZAF_NULLP(ZafWindowObject)); else if (object->SupportObject()) object = (ZafWindowObject *)ZafList::Get(support.Index(object)); // Check for an added page. if (object == Current()) return (object); else if (Index(object) == -1) { // Create the notebook tab. ZafWindow *window = DynamicPtrCast(object, ZafWindow); // Get the hotkey character. ZafWindowObject *title = window->Title(); ZafNotebookTab *tab = new ZafNotebookTab((ZafIChar *)window->Text()); if (title) { ZafEventStruct tEvent(S_HOTKEY_INFO_GET); title->Event(tEvent); tab->SetHotKey(tEvent.key.value, (int)tEvent.key.shiftState); } tab->SetDisabled(window->Disabled()); ZafWindowObject *tabPosition = position; if (tabPosition) tabPosition = tabControl->Get(Index(position)); tabControl->Add(tab, tabPosition); if (!tabControl->firstVisible) tabControl->firstVisible = tab; if (!tabControl->currentTab) tabControl->SetCurrentTab(tab); // Remove invalid support objects. for (ZafWindowObject *wObject = window->SupportFirst(); wObject; ) { // Remove invalid support objects (geometry manager is valid). ZafNumberID objID = wObject->NumberID(); if (objID < 0 && objID != ZAF_NUMID_GEOMETRY) { ZafWindowObject *tobject = wObject->Next(); window->Subtract(wObject); delete wObject; wObject = tobject; } else wObject = wObject->Next(); } // Add the notebook page. ZafWindow::Add(object, position); // Pages can't be considered to be overlapping. object->overlapped = false; // Non-current pages have visible false so they don't draw. if (object != current) object->SetVisible(false); if (screenID) Event(N_SIZE); } return (object);}ZafEventType ZafNotebook::DispatchMouseEvent(const ZafEventStruct &event){ ZafEventType ccode = LogicalEvent(event); // This object behaves as an atom for mouse events not over the client. ZafPositionStruct mousePosition = event.position; if (tabControl && tabControl->zafRegion.Overlap(mousePosition)) { if (editMode) tabControl->Event(event); ccode = ZafWindowObject::DispatchMouseEvent(event); } else if (clientRegion.Overlap(mousePosition) && current) ccode = Current()->DispatchMouseEvent(event); else ccode = ZafWindow::DispatchMouseEvent(event); return (ccode);}ZafWindowObject *ZafNotebook::FindMouseObject(const ZafEventStruct &event){ // If the object is disabled or not visible return a null pointer. if (Disabled() || !Visible()) return (ZAF_NULLP(ZafWindowObject)); ZafPositionStruct position; position.line = event.osEvent.y; position.column = event.osEvent.x; position.coordinateType = ZAF_PIXEL; ZafPositionStruct mousePosition = ConvertToZafPosition(this, &position); ZafWindowObject *mouseObject = 0; // This object behaves as an atom for mouse events not over the client. if (tabControl && tabControl->zafRegion.Overlap(mousePosition)) mouseObject = this; else if (clientRegion.Overlap(mousePosition) && current) mouseObject = Current()->FindMouseObject(event); else mouseObject = this; return (mouseObject);}#if defined(ZAF_DEFAULT_DRAW)ZafEventType ZafNotebook::ClassDraw(const ZafEventStruct &event, ZafEventType ccode){ // Compute the actual draw region. ZafRegionStruct drawRegion = BeginDraw(); if (Bordered()) drawRegion--; DrawBackground(drawRegion, ccode); EndDraw(); return (ccode);}ZafEventType ZafNotebook::DrawFrame(const ZafEventStruct &, ZafEventType ccode){ ZafRegionStruct drawRegion = BeginDrawFrame(); if (bordered) DrawBorder(drawRegion, ccode); DrawShadow(drawRegion, 0, ccode); EndDraw(); return (ccode);}ZafEventType ZafNotebook::DrawShadow(ZafRegionStruct ®ion, int, ZafEventType ccode){ ZafPaletteStruct lightShadow; ZafPaletteStruct darkShadow; ZafPaletteStruct whiteShadow; ZafPaletteStruct blackShadow; ShadowPalettes(ZAF_PM_ANY_STATE, &lightShadow, &darkShadow, &whiteShadow, &blackShadow); // Bottom edge. display->SetPalette(blackShadow); display->Line(region.left, region.bottom, region.right, region.bottom); // Right edge. display->Line(region.right, region.top + tabHeight, region.right, region.bottom); // Bottom edge. display->SetPalette(darkShadow); display->Line(region.left + 1, region.bottom - 1, region.right - 1, region.bottom - 1); // Right edge. display->Line(region.right - 1, region.top + tabHeight, region.right - 1, region.bottom - 1); // Left edge. display->SetPalette(whiteShadow); display->Line(region.left, region.top + tabHeight, region.left, region.bottom - 1); display->Line(region.left + 1, region.top + tabHeight, region.left + 1, region.bottom - 2); region -= ZAF_BORDER_SIZE; return (ccode);}#endifZafEventType ZafNotebook::Event(const ZafEventStruct &event){ ZafEventType ccode = LogicalEvent(event); // Initialize the autoListener. This will call any preprocessing listeners providing // listenerStackCount = 1. When it is destroyed any postprocessing listeners will be // called if the listenerStackCount = 1. ZafAutoListener autoListener(this, event, ccode); // If an event listener processed the event and the library should do nothing with it return. if (event.processed) return (ccode); // Check for zinc events. switch (ccode) { case S_COMPUTE_SIZE: { ZafWindow::Event(event); // Compute the default tab sizes. if (!tabHeight) { //tabHeight = display->cellHeight; display->SetFont(LogicalPalette(ZAF_PM_TEXT, ZAF_PM_ANY_STATE).font); ZafRegionStruct sizeRegion = display->TextSize(ZAF_ITEXT("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")); tabHeight = zafRegion.top + sizeRegion.Height() + 2; } } break; case N_SIZE: { ZafWindowObject *object; // Adjust the page sizes. for (object = First(); object; object = object->Next()) { object->Event(S_COMPUTE_SIZE); ZafRegionStruct newRegion; newRegion.left = 0; newRegion.top = 0; newRegion.right = clientRegion.right - clientRegion.left; newRegion.bottom = clientRegion.bottom - clientRegion.top; newRegion -= ZAF_BORDER_SIZE; newRegion.coordinateType = clientRegion.coordinateType; object->SetRegion(newRegion); object->OSSize(); } } break; case L_BEGIN_SELECT: case L_CONTINUE_SELECT: case L_END_SELECT: case L_VIEW: { if (WindowManager()->dragObject) { ZafWindowObject::Event(event); break; } // Only mouse events not over the client should get here. ZafPositionStruct mousePosition = event.position; if (tabControl && tabControl->zafRegion.Overlap(mousePosition)) { // If the tab control is being overlapped for the first time // let it set the mouse cursor without making it the // window manager's mouseObject (that would mess up // help tips if the notebook had one). if (ccode == L_VIEW && mouseObject != tabControl) { ZafEventStruct mouseEvent = event; mouseEvent.type = N_MOUSE_ENTER; tabControl->Event(mouseEvent); mouseObject = tabControl; } else ccode = tabControl->Event(event); } else { // If nothing is overlapped, reset the mouse cursor. if (ccode == L_VIEW) { mouseObject = ZAF_NULLP(ZafWindowObject); EventManager()->SetDeviceState(E_MOUSE, DM_VIEW); } else ccode = ZafWindow::Event(event); } } break; case N_MOUSE_ENTER: ZafWindow::Event(event); mouseObject = ZAF_NULLP(ZafWindowObject); break; case S_HOT_KEY: if (tabControl->Event(event) == S_UNKNOWN) ccode = current ? Current()->Event(event) : S_UNKNOWN; break; // ----- Movement ----- case L_NEXT: case L_PREVIOUS: // Tab applies to current page only. Shouldn't change pages. ccode = Current()->Event(event); break; // ----- Unknown or error messages ----- default: ccode = ZafWindow::Event(event); break; } // Return the control code. return (ccode);}ZafRegionStruct ZafNotebook::MaxRegion(ZafWindowObject *object, ZafVtJustify vWeight, ZafHzJustify hWeight){ // Check for existing OS region. ZafRegionStruct region = ZafWindow::MaxRegion(object, vWeight, hWeight); // Getting client region. if (!object || object == this || !object->SupportObject()) // Tab control { // Reduce for shadow border. Shadow border on top drawn by tab control. region.left += ZAF_BORDER_SIZE; region.right -= ZAF_BORDER_SIZE; region.bottom -= ZAF_BORDER_SIZE; } return (region);}bool ZafNotebook::PageDisabled(int page){ ZafWindowObject *tab = tabControl->Get(page); return (tab->Disabled());}ZafEventType ZafNotebook::ScrollEvent(const ZafEventStruct &){ // No processing is done at this level. return (S_ERROR);}ZafWindowObject *ZafNotebook::Subtract(ZafWindowObject *object){ // Check for support objects. if (object->SupportObject() && (support.Index(object) != -1)) return (ZafWindow::Subtract(object)); // Save some page information, then remove the object. bool saveUpdate = AutomaticUpdate(); automaticUpdate = false; ZafWindow *page = DynamicPtrCast(object, ZafWindow); int index = Index(page); object = ZafWindow::Subtract(object); // Re-add the title to the page. if (page && index >= 0) { ZafNotebookTab *title = DynamicPtrCast(tabControl->Get(index), ZafNotebookTab); if (title) { tabControl->Subtract(title); ZafTitle *nTitle = new ZafTitle(title->Text()); nTitle->ZafButton::SetHotKey(title->HotKeyChar(), title->HotKeyIndex()); page->ZafWindow::Add(nTitle); delete title; } } // Defer the rest to the base class. automaticUpdate = saveUpdate; return (object);}// ----- Attributes ---------------------------------------------------------ZafIChar ZafNotebook::TabHotKeyChar(int page) const{ // Find the associated tab. ZafNotebookTab *tab = (ZafNotebookTab *)((page == -1) ? tabControl->Current() : tabControl->Get(page)); return (tab ? tab->HotKeyChar() : '\0');}int ZafNotebook::TabHotKeyIndex(int page) const{ // Find the associated tab. ZafNotebookTab *tab = (ZafNotebookTab *)((page == -1) ? tabControl->Current() : tabControl->Get(page)); return (tab ? tab->HotKeyIndex() : -1);}const ZafIChar *ZafNotebook::TabText(int page){ // Get the text. ZafWindowObject *object = (ZafWindowObject *)((page == -1) ? tabControl->Current() : tabControl->Get(page)); return (object ? object->Text() : ZAF_NULLP(ZafIChar));}int ZafNotebook::SetCurrentPage(int index){ if (CurrentPage() != index && index >= FirstPage() && index <= LastPage()) { // Turn drawing off for non-current page. if (current) Current()->SetVisible(false); // Make page current. ZafWindowObject *page = DynamicPtrCast(Get(index), ZafWindowObject); if (Focus()) page->SetFocus(true); else SetCurrent(page); page->SetVisible(true); // Update the tabs. tabControl->SetCurrentTab(index); // Send notification event. Event(N_CHANGE_PAGE); } // Return the current page. return (CurrentPage());}ZafIChar ZafNotebook::SetTabHotKey(int page, ZafIChar hotKeyChar, int index){ // Find the associated tab. ZafNotebookTab *tab = (ZafNotebookTab *)((page == -1) ? tabControl->Current() : tabControl->Get(page)); return (tab ? tab->SetHotKey(hotKeyChar, index) : '\0');}ZafError ZafNotebook::SetTabText(const ZafIChar *text, int page){ // Set the text. ZafWindowObject *object = (ZafWindowObject *)((page == -1) ? tabControl->Current() : tabControl->Get(page)); ZafError tError; if (object) { tError = object->SetText(text); ZafRegionStruct tRegion = object->zafRegion; tRegion.VtShift(-tabControl->firstVisible->zafRegion.top); tRegion.HzShift(-tabControl->firstVisible->zafRegion.left); tabControl->OSInvalidateRegion(&tRegion);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -